package old;

import java.util.LinkedList;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TabLayoutPanel;

public class ChatLog extends Composite {
	int width, height;
	
	// MainPanel mit allen Tabs
	TabLayoutPanel tabPanel = new TabLayoutPanel(2, Unit.EM);

	LinkedList<ChatTab> tabs = new LinkedList<ChatTab>();

	public ChatLog(int width, int height) {
		tabPanel.setPixelSize(width, height);
		
		// init names of users in groups
		createTabs();

		// Create a three-item tab panel, with the tab area 1.5em tall.
		
		for (ChatTab t : tabs) {
			tabPanel.add(t, t.tabName);
		}
		initWidget(tabPanel);
	}

	private void createTabs() {
		// input Groups
		tabs.clear();

		String g1Name = "All";
		String[] g1Members = { "..." };
		
		String g2Name = "IM_7";
		String[] g2Members = { "Julia, David, Martin, Pascal" };

		ChatTab tab1 = new ChatTab(width-10, height-10, g1Name, g1Members);
		ChatTab tab2 = new ChatTab(width-10, height-10, g2Name, g2Members);

		tabs.add(tab1);
		tabs.add(tab2);
	}

	public void addNewMessage(String newMessage) {		
		tabs.get(tabPanel.getSelectedIndex()).addNewMessage(newMessage);
	}
}
